﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ClassMySQL.Classes;
using System.Data;
using Library.Windows;
using Library.Properties;

namespace Library
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        // Данные для тестирования класса
        private static string _host = Settings.Default.host;
        private static string _db = Settings.Default.database;
        private static string _login = Settings.Default.login;
        private static string _password = Settings.Default.password;

        // Второй сервер
        //private static string _host = "kazaku5d.beget.tech";
        //private static string _db = "kazaku5d_pc1";
        //private static string _login = "kazaku5d_pc1";
        //private static string _password = "123456_shask";
        public MainWindow()
        {
            InitializeComponent();
            StartApp();
            //MessageBox.Show(Test());
            //Test();
        }

        private void StartApp()
        {
            ServerMySQL.DB_Load(_host, _db, _login, _password);
            if (!ServerMySQL.CheckConnect())
            {
                MessageBox.Show("Ошибка соединения");
            }
        }

        private string Test()
        {
            string result = "";
            DataTable dt = ServerMySQL.GetDataTable("clients");
            object?[] row = dt.Rows[2].ItemArray;
            DateTime dr = Convert.ToDateTime(row[3]);
            

            result = row[1].ToString() + " " + row[2].ToString();
            result += " " + dr.ToString("dd MMMM yyyy");
            return result;
        }

        private void menuClient_Click(object sender, RoutedEventArgs e)
        {
            Clients window = new Clients();
            window.ShowDialog();
        }

        private void menuSettings_Click(object sender, RoutedEventArgs e)
        {
            Window set = new SettingsApp();
            set.ShowDialog();
        }

        private void menuAuthor_Click(object sender, RoutedEventArgs e)
        {
            Window window = new Authors();
            window.ShowDialog();
        }

        private void menuGenres_Click(object sender, RoutedEventArgs e)
        {
            Window window = new Genres();
            window.ShowDialog();
        }

        private void menuBooks_Click(object sender, RoutedEventArgs e)
        {
            Window window = new Books();
            window.ShowDialog();
        }
    }
}